# 鸢尾花数据分类
# MLPClassifier用法网址：https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPClassifier.html#sklearn.neural_network.MLPClassifier
# 导入所需的库
from sklearn.neural_network import MLPClassifier
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

# Step 1: 导入iris数据集
iris = load_iris()
X = iris.data
y = iris.target

# Step 2: 用留出法分割训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Step 3: 利用BP神经网络训练网络并给出测试数据集的分类结果
mlp = MLPClassifier(hidden_layer_sizes=(10,), max_iter=1000, alpha=1e-4,
                    solver='sgd', verbose=10, tol=1e-4, random_state=1,
                    learning_rate_init=.1)

mlp.fit(X_train, y_train)
predictions = mlp.predict(X_test)
